#define DEBUG
#include <cstdio>
#include <cmath>
#define MAXAB 1000000

using namespace std;

class Set {
public:
  int fa[MAXAB+1];

  void init(int n) {
    for (int i=1; i<=n; i++) {
      fa[i] = i;
    }
  }

  int getFa(int o) {
    if (fa[o]!=o) {
      fa[o] = getFa(fa[o]);
    }
    return fa[o];
  }
};

int max(int a, int b) {
  return a<b ? a : b;
}

int main() {
#ifdef DEBUG
  freopen("4661.in", "r", stdin);
  freopen("4661.out", "w", stdout);
#endif

  static bool prime[MAXAB+1];
  long long a, b, p;
  scanf("%lld %lld %lld", &a, &b, &p);
  static Set set;
  set.init(b-a+1);

  prime[1]=true;
  for (int i=2; i<=b-a+1; i++) {
    if (!prime[i]) {
      for (int j=2; i*j<=b-a+1; j++) {
	prime[i*j]=true;
      }
      if (i>=p) {
	long long x = a%i ? a/i+1 : a/i;
	for (long long j=x; i*j<=b; j++) {
	  if (set.getFa(x*i-a+1)!=set.getFa(i*j-a+1)) {
	    set.fa[set.getFa(i*j-a+1)] = set.getFa(x*i-a+1);
	  }
	}
      }
    }
  }

  static bool book[MAXAB+1];
  int cnt=0;
  for (int i=1; i<=b-a+1; i++) {
    if (!book[set.getFa(i)]) {
      book[set.getFa(i)]=true;
      cnt++;
    }
  }
  printf("%d", cnt);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
